package com.jiu345.users.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.jiu345.users.pojo.Member;
import com.jiu345.users.pojo.bo.AuthBo;
import com.jiu345.users.pojo.vo.AuthVo;
import com.jiu345.users.service.IAuthService;
import com.jiu345.users.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * package:AuthController
 *
 * @author MrLei QQ:235921049
 * desc:用户登录
 * @Date 2024.07.05 15:13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/user")
public class AuthController extends BaseController {
    private final IAuthService authService;
    /*用户注册*/
    @PostMapping("/register")
    public R<Member> register(@Validated @RequestBody AuthBo bo){

        return authService.register(bo);
    }


    /*用户登录*/
    @PostMapping("/login")
    public R<AuthVo> login (@RequestBody AuthBo bo){
        return authService.login(bo);
    }
    /*退出登录*/
    @PostMapping("/logout")
    public R<String> logout(){
        StpUtil.logout();
        return R.ok();
    }
    /*TODO 微信登录*/
    @PostMapping("/wxCheck")
    public String wxSignatureCheck(
        @RequestParam(value = "signature") String signature,
        @RequestParam(value="timestamp") String timestamp,
        @RequestParam(value="nonce") String nonce,
        @RequestParam(value="echostr") String echostr
    ){
        System.out.println("微信请求结果"+ echostr);
        return echostr;
    }


}
